package com.chixing.controller;

import com.chixing.service.HotelService;
import com.chixing.util.ServerResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class HotelController {
    @Autowired
    private HotelService hotelService;
    //根据主键查询
    @GetMapping("/hotel/{id}/house")
    @ResponseBody
    public ModelAndView getById(@PathVariable("id") Integer id){
        //1. 调用service
        ServerResponse serverResponse = hotelService.getById(id);
        //2. 数据绑定：serverResponse 绑定到响应页面
        ModelAndView mav = new ModelAndView();
        mav.addObject("serviceResponse", serverResponse); // 数据绑定
        //3. 跳转到响应页面
        mav.setViewName("house/house1");
        return mav;
    }


  /*  @GetMapping("house/{hotelArea}/{hotelType}/{minPrice}/{maxPrice}/{roomType}/{pageNum}")*/
    @GetMapping("hotel")
    @ResponseBody
    //多条件查询
    public ServerResponse getByConditions( @RequestParam(value = "hotelArea",required = false) String hotelArea,
                                           @RequestParam(value = "hotelType",required = false)String hotelType,
                                           @RequestParam(value = "minPrice",required = false)Float minPrice,
                                           @RequestParam(value = "maxPrice",required = false)Float maxPrice,
                                           @RequestParam(value = "roomType",required = false)String roomType,
                                           @RequestParam(value = "pageNum",required = false)Integer pageNum){
                 if(pageNum == null)
                 pageNum = 1;
        return hotelService.getByConditions(hotelArea, hotelType, minPrice, maxPrice, roomType, pageNum);
    }
    @GetMapping("house/shaixuan")
    public ModelAndView getAll(){
        ServerResponse serverResponse = hotelService.getAll();
        ModelAndView mav = new ModelAndView();
        mav.addObject("serverResponse",serverResponse);
        mav.setViewName("houses/house");
        return mav;
    }
    }




